package com.health.mapp.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.health.db.model.ImMsgNotice;
import com.health.db.model.ImMsgNoticeExample;
import com.health.db.service.msg.ImMsgNoticeService;
import com.health.mapp.bean.CheckSMSReq;
import com.health.mapp.bean.CheckSMSResp;
import com.health.mapp.bean.Header;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

public class CheckSMSImpl implements ActionInterface {

	private ImMsgNoticeService imMsgNoticeService  ;
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		
		CheckSMSReq req = (CheckSMSReq) reqBean;
		CheckSMSResp resp = new CheckSMSResp();
		String userPhone =req.getUserPhone();
		String sms =req.getSms();
		
		if (StringUtils.isBlank(userPhone)||StringUtils.isBlank(sms)) {
			resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
			resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
			return resp;
		}
		
		ImMsgNoticeExample notice = new ImMsgNoticeExample();
		notice.setRandom(sms);
		notice.setNoticeReceiveAddress(userPhone);
		notice.setIsUsedFlag((short) 1);
		List<ImMsgNotice> list=imMsgNoticeService.selectByExample(notice);
		
		if (list.size()!=1) {
			resp.setErrorCode(ResultCode.SMS_ERROR);
			resp.setErrorMsg(ResultCode.SMS_ERROR_NOTE);
			return resp;
		}
		imMsgNoticeService.updateForUserd(notice);
		//do it bobo
		return resp;
	}
	/**
	 * @return the imMsgNoticeService
	 */
	public ImMsgNoticeService getImMsgNoticeService() {
		return imMsgNoticeService;
	}
	/**
	 * @param imMsgNoticeService the imMsgNoticeService to set
	 */
	public void setImMsgNoticeService(ImMsgNoticeService imMsgNoticeService) {
		this.imMsgNoticeService = imMsgNoticeService;
	}

	
	
}
